﻿using Microsoft.Extensions.ObjectPool;

namespace zijian666.Data;

internal class PooledObjectPolicy<T>(Action<T>? returnning = null)
    : DefaultPooledObjectPolicy<T>
    where T : class, new()
{
    private readonly Action<T>? _returnning = returnning;

    public override bool Return(T obj)
    {
        if (obj is IPooledObject pooled)
        {
            pooled.OnRetrunning();
        }
        _returnning?.Invoke(obj);
        return base.Return(obj);
    }
}
